var jscomp = {
    scope: {}
};

jscomp.defineProperty = "function" == typeof Object.defineProperties ? Object.defineProperty : function(target, property, descriptor) {
    if (descriptor.get || descriptor.set) throw new TypeError("ES3 does not support getters and setters.");
    target != Array.prototype && target != Object.prototype && (target[property] = descriptor.value);
}, jscomp.getGlobal = function(target) {
    return "undefined" != typeof window && window === target ? target : "undefined" != typeof global ? global : target;
}, jscomp.global = jscomp.getGlobal(void 0), jscomp.SYMBOL_PREFIX = "jscomp_symbol_", jscomp.initSymbol = function() {
    jscomp.initSymbol = function() {}, jscomp.global.Symbol || (jscomp.global.Symbol = jscomp.Symbol);
}, jscomp.symbolCounter_ = 0, jscomp.Symbol = function(description) {
    return jscomp.SYMBOL_PREFIX + (description || "") + jscomp.symbolCounter_++;
}, jscomp.initSymbolIterator = function() {
    jscomp.initSymbol();
    var iteratorSymbol = jscomp.global.Symbol.iterator;
    iteratorSymbol || (iteratorSymbol = jscomp.global.Symbol.iterator = jscomp.global.Symbol("iterator")), "function" != typeof Array.prototype[iteratorSymbol] && jscomp.defineProperty(Array.prototype, iteratorSymbol, {
        configurable: !0,
        writable: !0,
        value: function() {
            return jscomp.arrayIterator(this);
        }
    }), jscomp.initSymbolIterator = function() {};
}, jscomp.arrayIterator = function(array) {
    var index = 0;
    return jscomp.iteratorPrototype(function() {
        return index < array.length ? {
            done: !1,
            value: array[index++]
        } : {
            done: !0
        };
    });
}, jscomp.iteratorPrototype = function(nextFunction) {
    return jscomp.initSymbolIterator(), (nextFunction = {
        next: nextFunction
    })[jscomp.global.Symbol.iterator] = function() {
        return this;
    }, nextFunction;
}, jscomp.makeIterator = function(iterable) {
    jscomp.initSymbolIterator();
    var iterator = iterable[Symbol.iterator];
    return iterator ? iterator.call(iterable) : jscomp.arrayIterator(iterable);
}, jscomp.arrayFromIterator = function(iterator) {
    for (var result, array = []; !(result = iterator.next()).done; ) array.push(result.value);
    return array;
}, jscomp.arrayFromIterable = function(iterable) {
    return iterable instanceof Array ? iterable : jscomp.arrayFromIterator(jscomp.makeIterator(iterable));
};

var app = getApp(), dataApi = require("../../provider/dataApi.js");

require("../../provider/pipe.js");

Page({
    data: {
        title: "题型练习",
        statusBarHeight: "",
        titleBarHeight: "",
        list: [],
        isloading: !0,
        params: "",
        isShowTest: !1,
        showPay: !1,
        item: {},
        page: 1,
        totalPage: "",
        isData: !0,
        isSon: 2
    },
    onLoad: function(options) {
        if (wx.getStorageSync("uid")) {
            var model = wx.getSystemInfoSync().model.slice(0, 6), shortModel = wx.getSystemInfoSync().model.slice(0, 4), isIos = !1;
            "iPhone" != model && "iPad" != shortModel || (isIos = !0), this.setData({
                statusBarHeight: app.globalData.statusBarHeight,
                titleBarHeight: app.globalData.titleBarHeight,
                title: app.globalData.title,
                isIos: isIos
            }), "{}" !== JSON.stringify(options) && this.setData({
                params: options,
                title: "全真模拟试卷列表",
                isShowTest: !0
            }), this.data.isShowTest || (this.setData({
                lib_id: app.globalData.lib_id
            }), this.getSequence());
        } else wx.navigateTo({
            url: "/pages/login/login"
        });
    },
    getSequence: function() {
        var self = this;
        dataApi.sequence({
            uid: wx.getStorageSync("uid"),
            op: "getalltypes",
            lib_id: this.data.lib_id
        }).then(function(response) {
            if (console.log(response), response.data.type_list) {
                var typeList = response.data.type_list, hasData = !1;
                0 < typeList.length && (hasData = !0), self.setData({
                    list: typeList,
                    isSon: response.data.son,
                    isloading: !1,
                    isData: hasData
                });
            }
            wx.stopPullDownRefresh();
        }).catch(function(error) {
            console.log(error);
        });
    },
    getExamList: function(page) {
        var self = this;
        dataApi.getExamList({
            uid: wx.getStorageSync("uid"),
            page: page
        }).then(function(response) {
            if (console.log(response), response.data.list) {
                var combinedList, hasData = !1;
                0 < (combinedList = [].concat(jscomp.arrayFromIterable(self.data.list), jscomp.arrayFromIterable(response.data.list))).length && (hasData = !0), 
                self.setData({
                    list: combinedList,
                    totalPage: Math.ceil(response.data.total / response.data.psize),
                    isData: hasData,
                    isloading: !1
                });
            }
            wx.stopPullDownRefresh();
        }).catch(function(error) {
            console.log(error);
        });
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    iosTip: function() {
        wx.showModal({
            cancelText: "关闭",
            confirmText: "联系客服",
            content: "由于相关规范，ios功能暂不可用，如有问题请联系客服",
            showCancel: !0,
            title: "提示",
            success: function(response) {
                response.confirm && wx.navigateTo({
                    url: "/pages/contactService/contactService"
                });
            }
        });
    },
    goLx: function(event) {
        if (this.data.params) {
            var item = event.currentTarget.dataset.item;
            1 != item.is_repeat && 0 < item.do_number ? wx.showToast({
                title: "不可重复答题",
                icon: "none"
            }) : wx.navigateTo({
                url: "../exam-before-see/exam-before-see?exam_type=1&paperid=" + event.currentTarget.id
            });
        } else 1 == this.data.isSon ? 8 != (event = event.currentTarget.id) ? (app.globalData.op = "qtype", 
        app.globalData.id = event, wx.navigateTo({
            url: "../practice/practice"
        })) : wx.navigateTo({
            url: "/pages/shortAnswerList/shortAnswerList"
        }) : (event = event.currentTarget.id, app.globalData.op = "qtype", app.globalData.id = event, wx.navigateTo({
            url: "../practice/practice"
        }));
    },
    goPayPopup: function(event) {
        1 != (event = event.currentTarget.dataset.item).is_repeat && 0 < event.do_number ? wx.showToast({
            title: "本套试卷暂不可购买",
            icon: "none"
        }) : this.data.isIos && 2 == this.data.userInfo.IOS ? this.iosTip() : this.setData({
            item: event,
            showPay: !0
        });
    },
    getUserInfo: function() {
        var self = this;
        dataApi.userinfo({
            uid: wx.getStorageSync("uid"),
            op: "getinfo"
        }).then(function(response) {
            console.log(response), self.setData({
                userInfo: response.data.info
            });
        }).catch(function(error) {
            console.log(error);
        });
    },
    onShow: function() {
        this.data.isShowTest && (this.setData({
            page: 1,
            list: []
        }), this.getUserInfo(), this.getExamList(1));
    },
    closePayPopup: function() {
        this.setData({
            showPay: !1
        });
    },
    goPayBtn: function() {
        this.requestPayment();
    },
    requestPayment: function() {
        var self = this;
        dataApi.wxPay({
            uid: wx.getStorageSync("uid"),
            id: this.data.item.id,
            type: "4"
        }).then(function(response) {
            console.log(response), wx.requestPayment({
                timeStamp: String(response.data.timeStamp),
                nonceStr: response.data.nonceStr,
                package: response.data.package,
                signType: response.data.signType,
                paySign: response.data.paySign,
                success: function(response) {
                    console.log(response), wx.showToast({
                        icon: "success",
                        title: "支付成功"
                    }), self.setData({
                        showPay: !1
                    }), self.getExamList(1);
                },
                fail: function(response) {
                    wx.showToast({
                        icon: "none",
                        title: "支付失败,请重试~"
                    }), self.setData({
                        showPay: !1
                    });
                }
            });
        }).catch(function(error) {
            console.log(error);
        });
    },
    goVipBtn: function() {
        wx.navigateTo({
            url: "../vip/vip"
        });
    },
    onPullDownRefresh: function() {
        this.data.isShowTest ? (this.setData({
            page: 1,
            list: [],
            isloading: !0
        }), this.getExamList(1)) : this.getSequence();
    },
    onReachBottom: function() {
        var totalPages = parseInt(this.data.totalPage), currentPage = parseInt(this.data.page);
        currentPage < totalPages && (this.setData({
            page: currentPage + 1
        }), this.getExamList(this.data.page));
    },
    onShareAppMessage: function() {}
});